/*
 * Copyright © 2017-2023 TemplateFactory(xiaoymin@foxmail.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */


package com.github.xiaoymin.template;

import cn.hutool.core.io.FileUtil;
import com.github.xiaoymin.template.config.Configuration;
import org.apache.maven.project.MavenProject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.File;

/***
 *
 * @since template-engine 1.0
 * @author <a href="mailto:xiaoymin@foxmail.com">xiaoymin@foxmail.com</a> 
 * 2020/06/06 14:52
 */
public class TemplateEngine {
    
    static Logger logger = LoggerFactory.getLogger(TemplateEngine.class);
    
    public static final String VERSION = "1.0";
    
    /**
     * 开始生成
     * @param configurationFile
     */
    public static void generator(File configurationFile, MavenProject mavenProject) {
        if (!configurationFile.exists()) {
            logger.info("Template Configuration File Un Exists,FilePath:{}", configurationFile.getPath());
            return;
        }
        Configuration templateConfiguration = new Configuration(configurationFile, mavenProject);
        templateConfiguration.parse();
        templateConfiguration.execute();
        logger.info("TemplateEngine Finished。...");
    }
    
    public static void generator(File configurationFile, String baseDir) {
        if (!configurationFile.exists()) {
            logger.info("Template Configuration File Un Exists,FilePath:{}", configurationFile.getPath());
            return;
        }
        Configuration templateConfiguration = new Configuration(configurationFile, baseDir);
        templateConfiguration.parse();
        templateConfiguration.execute();
        logger.info("TemplateEngine Finished...");
    }
    
    public static void print(File file) {
        String str = FileUtil.readString(file, "UTF-8");
        logger.info("content:{}", str);
    }
}
